package cn.group7.padserver.service.impl;

import cn.group7.padserver.dao.SellPurchaseDao;
import cn.group7.padserver.entity.SellPurchase;
import cn.group7.padserver.service.SellPurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 谷汉斌
 * @description
 * @createTime 2024/8/4 下午4:36
 */
@Service
public class SellPurchaseServiceImpl implements SellPurchaseService {

    @Autowired
    private SellPurchaseDao sellPurchaseDao;

    @Override
    public boolean add(SellPurchase sellPurchase) {
       return sellPurchaseDao.insertSelective(sellPurchase)==1;
    }

    @Override
    public List<SellPurchase> selectByName() {
        //获取用户名
        UserDetails principal = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String name = principal.getUsername();
        return sellPurchaseDao.selectByName(name);
    }
}
